#include <stdlib.h>
#include <clutter/clutter.h>

#define WINDOWS_WIDTH 400
#define WINDOWS_HEIGHT 400
#define UNUSED(x) (void)x

static gboolean on_actor_enter(ClutterStage *stage, ClutterEvent *event, gpointer data)
{
    UNUSED(stage);
    UNUSED(event);
    UNUSED(data);
    printf("on_actor_enter \n");

    return TRUE;
}

static gboolean on_actor_leave(ClutterStage *stage, ClutterEvent *event, gpointer data)
{
    UNUSED(stage);
    UNUSED(event);
    UNUSED(data);
    printf("on_actor_leave \n");
    
    return TRUE;
}

static gboolean on_actor_button_press(ClutterStage *stage, ClutterEvent *event, gpointer data)
{
    UNUSED(stage);
    UNUSED(event);
    UNUSED(data);
    printf("on_actor_button_press \n");
    
    return TRUE;
}

static gboolean on_actor_button_release(ClutterStage *stage, ClutterEvent *event, gpointer data)
{
    UNUSED(stage);
    UNUSED(event);
    UNUSED(data);
    printf("on_actor_button_release \n");
    
    return TRUE;
}

static gboolean on_actor_motion_event(ClutterStage *stage, ClutterEvent *event, gpointer data)
{
    UNUSED(stage);
    UNUSED(event);
    UNUSED(data);
    printf("on_actor_motion_event \n");
    
    return TRUE;
}

static gboolean on_key_press_event (ClutterStage *stage,
                    ClutterEvent *event,
                    gpointer      user_data)
{
    UNUSED(stage);
    UNUSED(user_data);
    printf("key-code=%d \n",clutter_event_get_key_symbol (event));
    return CLUTTER_EVENT_PROPAGATE;
}

int main(int argc , char * argv[])
{
    if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
    {
        return EXIT_FAILURE;
    }

    ClutterActor *stage = clutter_stage_new();
    clutter_stage_set_title (CLUTTER_STAGE (stage), "ClutterSignal");
    clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE);
    clutter_actor_set_size(stage, WINDOWS_WIDTH, WINDOWS_HEIGHT);
    clutter_actor_set_background_color (stage, CLUTTER_COLOR_Green);
    g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);


    /* add button */
    ClutterActor *button = clutter_actor_new ();
    clutter_actor_set_name (button, "button");
    clutter_actor_set_size (button, 100, 100);
    clutter_actor_set_margin_top (button, 40);
    clutter_actor_set_margin_left (button, 40);
    clutter_actor_set_margin_right (button, 10);
    clutter_actor_set_margin_bottom (button, 10);
    clutter_actor_set_background_color (button, CLUTTER_COLOR_DarkBlue);
    clutter_actor_add_child (stage, button);
    clutter_actor_set_reactive (button, TRUE);
    g_signal_connect (button, "enter-event", G_CALLBACK (on_actor_enter), NULL);
    g_signal_connect (button, "leave-event", G_CALLBACK (on_actor_leave), NULL);
    g_signal_connect (button, "button-press-event", G_CALLBACK (on_actor_button_press), NULL);
    g_signal_connect (button, "button-release-event", G_CALLBACK (on_actor_button_release), NULL);
    g_signal_connect (button, "motion-event", G_CALLBACK (on_actor_motion_event), NULL);

    g_signal_connect (stage, "key-press-event", G_CALLBACK (on_key_press_event), NULL);
    clutter_actor_show (stage);
    clutter_main();
    return EXIT_SUCCESS;
}